/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projetluc;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JLabel;

/**
 *
 * @author Lone_Wolf
 */
public class SearchResult extends JButton {

    private TypeDonnees type;
    private Client client;
    private Employe employe;
    private Entree entree;
    private Facture facture;
    private GridBagLayout gbl;
    private GridBagConstraints gbc;

    public SearchResult(TypeDonnees type, Object donnees) {
        this.type = type;
        this.setPreferredSize(new Dimension(457, 25));
        switch (type) {
            case CLIENT:
                client = (Client) donnees;
                buildClient();
                break;
            case EMPLOYE:
                employe = (Employe) donnees;
                buildEmploye();
                break;
            case ENTREE:
                entree = (Entree) donnees;
                buildEntree();
                break;
            case FACTURE:
                facture = (Facture) donnees;
                buildFacture();
                break;
        }
    }

    private void buildClient() {
        this.setHorizontalAlignment(JButton.LEADING);
        this.setText("<html><b><i><font size=+0>" + client.getNom() + "</b></i></font>"
                + "     ---     " + client.getCode() + "</html>");
    }

    private void buildEmploye() {
        this.setHorizontalAlignment(JButton.LEADING);
        this.setText("<html><b><i><font size=+0>" + employe.getNom() + "</b></i></font>"
                + "     ---     " + employe.getInitiales() + "</html>");
    }

    private void buildEntree() {
        this.setHorizontalAlignment(JButton.LEADING);
        this.setText("<html><b><i><font size=+0>" + entree.getEmploye().getNom() + "</b></i></font>"
                + "     ---     " + entree.getTache() + " --- "+ entree.getTemps()
                + " heures @ " + entree.getSalaire() + " $/h pour " + entree.getCout() + "$ --- le "
                + entree.getDay() + "-"
                + entree.getMonth() + "-"
                + entree.getYear() + "</html>");
    }

    private void buildFacture() {
        this.setHorizontalAlignment(JButton.LEADING);
        this.setText("<html><b><i><font size=+0>" + facture.getNumero() + "</b></i></font>"
                + "     ---     " + facture.getClient().getCode() + " - " + facture.getClient().getNom()
                + " --- " + facture.getDate_S() + "</html>");
    }

    private void makeSeparator() {
        JLabel sep = new JLabel(" ");
        gbc.gridwidth = gbc.REMAINDER;
        gbl.setConstraints(sep, gbc);
        this.add(sep);
        gbc.gridwidth = gbc.CENTER;
        gbc.weighty = 0;
    }

    private void makeBorder() {
        gbc.weightx = 0.1;
        JLabel sep = new JLabel(" ");
        gbl.setConstraints(sep, gbc);
        this.add(sep);
        gbc.gridwidth = gbc.CENTER;
    }

    public Client getClient() {
        return client;
    }

    public Employe getEmploye() {
        return employe;
    }

    public Entree getEntree() {
        return entree;
    }
    
    public Facture getFacture(){
        return facture;
    }

    public TypeDonnees getType() {
        return type;
    }
}
